# 定义商品分类三级联动工具方法
from apps.contents.models import GoodsChannel



def get_goodsclass():
    good_dict = {}

    # 查询所有的频道，遍历获取每一个频道
    channels = GoodsChannel.objects.all().order_by('group_id', 'sequence')
    for erery_channel in channels:
        # 获取每一个频道组的ID
        group_id = erery_channel.group.id

        # 判断每组是否存在字典中，如果不在以ID为KEY,构建字典结构
        # 查询需要数据，填充字典数据结构
        if group_id not in good_dict:
            good_dict[group_id] = {'channels': [], 'sub_cats': []}

        # class1 = group_id
        # good_dict[group_id]['channels'].append({
        #     "id": erery_channel.id,
        #     "name": group_id.name,
        #     "url": erery_channel.url
        # })

    pass


# 定义获取面包屑导航工具方法
def get_crumbs(category3):
    """
    面包屑导航
    :param category3:
    :return:parent
    """
    category2 = category3.parent
    category1 = category2.parent

    crumbs = {
        'cat1': category1.name,
        'cat2': category2.name,
        'cat3': category3.name
    }

    return crumbs
